import { constantRoutes, asyncRoutes } from '../../router/index'
const state = {
  routes: constantRoutes
}

const mutations = {
  SET_ROUTES (state, payload) {
    state.routes = [...constantRoutes, ...payload]
  }
}

const actions = {
  getNewRoutes (content, menu) {
    const newRouted = []
    menu.forEach(item => {
      const res = asyncRoutes.filter(value => {
        return value.path === '/' + item
      })
      newRouted.push(...res)
    })
    content.commit('SET_ROUTES', newRouted)
    return newRouted
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
